package com.gvjn.ant.customtasks.spring;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class SpringCustomAntTask extends Task {

	String inWebXML;
	String outWebXML;
    String inSpringXML;
    String outSpringXML;
    String mapFile;
    String removeComments;
    String removeEmptyLines;
    String removeLineBreaks;
    String removeWhitespaces;
    public void setMapFile(String mapFile) {
		this.mapFile = mapFile;
	}
	public void setInWebXML(String inWebXML) {
		this.inWebXML = inWebXML;
	}
	public void setOutWebXML(String outWebXML) {
		this.outWebXML = outWebXML;
	}
	public void setInSpringXML(String inSpringXML) {
		this.inSpringXML = inSpringXML;
	}
	public void setOutSpringXML(String outSpringXML) {
		this.outSpringXML = outSpringXML;
	}
    public void setRemoveComments(String removeComments) {
		this.removeComments = removeComments;
	}
	public void setRemoveEmptyLines(String removeEmptyLines) {
		this.removeEmptyLines = removeEmptyLines;
	}
	public void setRemoveLineBreaks(String removeLineBreaks) {
		this.removeLineBreaks = removeLineBreaks;
	}
	public void setRemoveWhitespaces(String removeWhitespaces) {
		this.removeWhitespaces = removeWhitespaces;
	}

	public void execute() {
        if (inWebXML==null) {
            throw new BuildException("No web.xml supplied.");
        }
        if (inSpringXML==null) {
            throw new BuildException("No spring-servlet.xml supplied.");
        }
        if (mapFile==null) {
            throw new BuildException("No map_file supplied.");
        }

        log("Initiating XML parsing...");
        boolean result = ProcessFiles.init(inWebXML,outWebXML,inSpringXML,outSpringXML,mapFile,
        		removeComments,removeEmptyLines,removeLineBreaks,removeWhitespaces);
        if(result)
        	log("Finished, modified files created.");
        else
        	log("There was some error!");
    }
}